<template>
	<view class="message-list">
		<view class="message-item" v-for="(item,index) in commentList" :key="index">
			<view class="user-info">
				<image :src="item.heard_img" mode=""></image>
				<view class="user-info-right">
					<view class="name">{{item.nickname}}</view>
					<view class="time">{{item.add_time}}</view>
				</view>
			</view>
			<view class="comment">{{item.content}}</view>
		</view>
		<lw-nodata v-if="commentList.length == 0"></lw-nodata>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" v-if="commentList.length > 4" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				case_id: '',
				commentList: [],
				page: 0,
				more: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
			};
		},
		onLoad(e) {
			this.case_id = e.case_id
			this.init()
		},
		methods: {
			init() {
				let data = {
					case_id: this.case_id,
					order_by: 'add_time',
					page: this.page,
					limit: 10,
					asc: 1
				}
				this.$u.apiWei.ExampleCommentList(data).then(res => {
					res.datas.forEach((item) => {
						this.commentList.push(item)
					})
					if (res.datas.length == 10) {
						this.more = true
					} else {
						this.more = false
					}


				})
			}
		},
		onPullDownRefresh() {
			this.page = 0
			this.commentList = []
			this.init()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);

		},
		onReachBottom() {
			this.status = 'loading';
			setTimeout(() => {
				this.status = 'nomore';
			}, 1000)
			if (!this.more) return;
			this.page++;
			this.init()
		},
	}
</script>

<style lang="scss">
	.message-list {
		margin: 32rpx 0;
		white-space: nowrap;
		width: 100%;

		.message-item {
			margin: 20rpx auto 0 auto;
			padding: 30rpx 30rpx;
			width: 90%;
			height: 247rpx;
			background: #F8F8F8;
			border: 1px solid #F2F2F2;
			border-radius: 8rpx;
			box-sizing: border-box;

			image {
				display: block;
				width: 66rpx;
				height: 66rpx;
				border-radius: 50%;
			}
		}

		.user-info {
			display: flex;

			.user-info-right {
				margin-left: 20rpx;

				.name {
					font-size: 24rpx;
					font-weight: bold;
					color: #333333;
				}

				.time {
					font-size: 20rpx;
					color: #909090;
				}
			}
		}

		.comment {
			margin: 30rpx auto 0 auto;
			width: 100%;
			font-size: 26rpx;
			color: #141414;
			//超过两行省略号
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			white-space: pre-wrap;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}
	}
</style>
